View

Subclass of [class@Gtk.TextView].

GtkSourceView is the main class of the GtkSourceView library. Use a [class@Buffer] to display text with a GtkSourceView.

This class provides:

- Show the line numbers; - Show a right margin; - Highlight the current line; - Indentation settings; - Configuration for the Home and End keyboard keys; - Configure and show line marks; - And a few other things.

An easy way to test all these features is to use the test-widget mini-program provided in the GtkSourceView repository, in the tests/ directory.

GtkSourceView as GtkBuildable

The GtkSourceView implementation of the [iface@Gtk.Buildable] interface exposes the [property@View:completion] object with the internal-child "completion".

An example of a UI definition fragment with GtkSourceView:

<object class="GtkSourceView" id="source_view">
<property name="tab-width">4</property>
<property name="auto-indent">True</property>
<child internal-child="completion">
<object class="GtkSourceCompletion">
<property name="select-on-show">False</property>
</object>
</child>
</object>

Changing the Font

Gtk CSS provides the best way to change the font for a GtkSourceView in a manner that allows for components like [class@Map] to scale the desired font.

GtkCssProvider *provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider,
"textview { font-family: Monospace; font-size: 8pt; }",
-1,
NULL);
gtk_style_context_add_provider (gtk_widget_get_style_context (view),
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);

If you need to adjust the font or size of font within a portion of the document only, you should use a [class@Gtk.TextTag] with the [property@Gtk.TextTag:family] or [property@Gtk.TextTag:scale] set so that the font size may be scaled relative to the default font set in CSS.

class View : TextView {}

Constructors

this
this(GtkSourceView* gtkSourceView, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this()

Creates a new GtkSourceView.

this
this(Buffer buffer)

Creates a new #GtkSourceView widget displaying the buffer @buffer.

Members

Functions

addOnChangeCase
gulong addOnChangeCase(void delegate(GtkSourceChangeCaseType, View) dlg, ConnectFlags connectFlags)

Keybinding signal to change case of the text at the current cursor position.

addOnChangeNumber
gulong addOnChangeNumber(void delegate(int, View) dlg, ConnectFlags connectFlags)

Keybinding signal to edit a number at the current cursor position.

addOnJoinLines
gulong addOnJoinLines(void delegate(View) dlg, ConnectFlags connectFlags)

Keybinding signal to join the lines currently selected.

addOnLineMarkActivated
gulong addOnLineMarkActivated(void delegate(TextIter, uint, GdkModifierType, int, View) dlg, ConnectFlags connectFlags)

Emitted when a line mark has been activated (for instance when there was a button press in the line marks gutter).

addOnMoveLines
gulong addOnMoveLines(void delegate(bool, View) dlg, ConnectFlags connectFlags)

The signal is a keybinding which gets emitted when the user initiates moving a line.

addOnMoveToMatchingBracket
gulong addOnMoveToMatchingBracket(void delegate(bool, View) dlg, ConnectFlags connectFlags)

Keybinding signal to move the cursor to the matching bracket.

addOnMoveWords
gulong addOnMoveWords(void delegate(int, View) dlg, ConnectFlags connectFlags)

The signal is a keybinding which gets emitted when the user initiates moving a word.

addOnPushSnippet
gulong addOnPushSnippet(void delegate(Snippet, TextIter, View) dlg, ConnectFlags connectFlags)

The signal is emitted to insert a new snippet into the view.

addOnShowCompletion
gulong addOnShowCompletion(void delegate(View) dlg, ConnectFlags connectFlags)

The signal is a key binding signal which gets emitted when the user requests a completion, by pressing <keycombo><keycap>Control</keycap><keycap>space</keycap></keycombo>.

addOnSmartHomeEnd
gulong addOnSmartHomeEnd(void delegate(TextIter, int, View) dlg, ConnectFlags connectFlags)

Emitted when a the cursor was moved according to the smart home end setting.

getAutoIndent
bool getAutoIndent()

Returns whether auto-indentation of text is enabled.

getBackgroundPattern
GtkSourceBackgroundPatternType getBackgroundPattern()

Returns the #GtkSourceBackgroundPatternType specifying if and how the background pattern should be displayed for this @view.

getCompletion
Completion getCompletion()

Gets the [class@Completion] associated with @view.

getEnableSnippets
bool getEnableSnippets()

Gets the [property@View:enable-snippets] property.

getGutter
Gutter getGutter(GtkTextWindowType windowType)

Returns the [class@Gutter] object associated with @window_type for @view.

getHighlightCurrentLine
bool getHighlightCurrentLine()

Returns whether the current line is highlighted.

getHover
Hover getHover()

Gets the [class@Hover] associated with @view.

getIndentOnTab
bool getIndentOnTab()

Returns whether when the tab key is pressed the current selection should get indented instead of replaced with the \t character.

getIndentWidth
int getIndentWidth()

Returns the number of spaces to use for each step of indent.

getIndenter
IndenterIF getIndenter()

Gets the [property@View:indenter] property.

getInsertSpacesInsteadOfTabs
bool getInsertSpacesInsteadOfTabs()

Returns whether when inserting a tabulator character it should be replaced by a group of space characters.

getMarkAttributes
MarkAttributes getMarkAttributes(string category, int* priority)

Gets attributes and priority for the @category.

getRightMarginPosition
uint getRightMarginPosition()

Gets the position of the right margin in the given @view.

getShowLineMarks
bool getShowLineMarks()

Returns whether line marks are displayed beside the text.

getShowLineNumbers
bool getShowLineNumbers()

Returns whether line numbers are displayed beside the text.

getShowRightMargin
bool getShowRightMargin()

Returns whether a right margin is displayed.

getSmartBackspace
bool getSmartBackspace()

Returns %TRUE if pressing the Backspace key will try to delete spaces up to the previous tab stop.

getSmartHomeEnd
GtkSourceSmartHomeEndType getSmartHomeEnd()

Returns a [enum@SmartHomeEndType] end value specifying how the cursor will move when HOME and END keys are pressed.

getSpaceDrawer
SpaceDrawer getSpaceDrawer()

Gets the [class@SpaceDrawer] associated with @view.

getStruct
void* getStruct()

the main Gtk struct as a void*

getTabWidth
uint getTabWidth()

Returns the width of tabulation in characters.

getViewStruct
GtkSourceView* getViewStruct(bool transferOwnership)

Get the main Gtk struct

getVisualColumn
uint getVisualColumn(TextIter iter)

Determines the visual column at @iter taking into consideration the [property@View:tab-width] of @view.

indentLines
void indentLines(TextIter start, TextIter end)

Inserts one indentation level at the beginning of the specified lines. The empty lines are not indented.

pushSnippet
void pushSnippet(Snippet snippet, TextIter location)

Inserts a new snippet at @location

setAutoIndent
void setAutoIndent(bool enable)

If %TRUE auto-indentation of text is enabled.

setBackgroundPattern
void setBackgroundPattern(GtkSourceBackgroundPatternType backgroundPattern)

Set if and how the background pattern should be displayed.

setEnableSnippets
void setEnableSnippets(bool enableSnippets)

Sets the [property@View:enable-snippets] property.

setHighlightCurrentLine
void setHighlightCurrentLine(bool highlight)

If @highlight is %TRUE the current line will be highlighted.

setIndentOnTab
void setIndentOnTab(bool enable)

If %TRUE, when the tab key is pressed when several lines are selected, the selected lines are indented of one level instead of being replaced with a \t character. Shift+Tab unindents the selection.

setIndentWidth
void setIndentWidth(int width)

Sets the number of spaces to use for each step of indent when the tab key is pressed.

setIndenter
void setIndenter(IndenterIF indenter)

Sets the indenter for @view to @indenter.

setInsertSpacesInsteadOfTabs
void setInsertSpacesInsteadOfTabs(bool enable)

If %TRUE a tab key pressed is replaced by a group of space characters.

setMarkAttributes
void setMarkAttributes(string category, MarkAttributes attributes, int priority)

Sets attributes and priority for the @category.

setRightMarginPosition
void setRightMarginPosition(uint pos)

Sets the position of the right margin in the given @view.

setShowLineMarks
void setShowLineMarks(bool show)

If %TRUE line marks will be displayed beside the text.

setShowLineNumbers
void setShowLineNumbers(bool show)

If %TRUE line numbers will be displayed beside the text.

setShowRightMargin
void setShowRightMargin(bool show)

If %TRUE a right margin is displayed.

setSmartBackspace
void setSmartBackspace(bool smartBackspace)

When set to %TRUE, pressing the Backspace key will try to delete spaces up to the previous tab stop.

setSmartHomeEnd
void setSmartHomeEnd(GtkSourceSmartHomeEndType smartHomeEnd)

Set the desired movement of the cursor when HOME and END keys are pressed.

setTabWidth
void setTabWidth(uint width)

Sets the width of tabulation in characters.

unindentLines
void unindentLines(TextIter start, TextIter end)

Removes one indentation level at the beginning of the specified lines.

Static functions

getType
GType getType()

Variables

gtkSourceView
GtkSourceView* gtkSourceView;

the main Gtk struct

Inherited Members

From TextView

gtkTextView
GtkTextView* gtkTextView;

the main Gtk struct

getTextViewStruct
GtkTextView* getTextViewStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

__anonymous
mixin ScrollableT!(GtkTextView)
Undocumented in source.
getType
GType getType()
addChildAtAnchor
void addChildAtAnchor(Widget child, TextChildAnchor anchor)

Adds a child widget in the text buffer, at the given @anchor.

addOverlay
void addOverlay(Widget child, int xpos, int ypos)

Adds @child at a fixed coordinate in the GtkTextView's text window.

backwardDisplayLine
bool backwardDisplayLine(TextIter iter)

Moves the given @iter backward by one display (wrapped) line.

backwardDisplayLineStart
bool backwardDisplayLineStart(TextIter iter)

Moves the given @iter backward to the next display line start.

bufferToWindowCoords
void bufferToWindowCoords(GtkTextWindowType win, int bufferX, int bufferY, int windowX, int windowY)

Converts buffer coordinates to window coordinates.

forwardDisplayLine
bool forwardDisplayLine(TextIter iter)

Moves the given @iter forward by one display (wrapped) line.

forwardDisplayLineEnd
bool forwardDisplayLineEnd(TextIter iter)

Moves the given @iter forward to the next display line end.

getAcceptsTab
bool getAcceptsTab()

Returns whether pressing the <kbd>Tab</kbd> key inserts a tab characters.

getBottomMargin
int getBottomMargin()

Gets the bottom margin for text in the @text_view.

getBuffer
TextBuffer getBuffer()

Returns the GtkTextBuffer being displayed by this text view.

getCursorLocations
void getCursorLocations(TextIter iter, GdkRectangle strong, GdkRectangle weak)

Determine the positions of the strong and weak cursors if the insertion point is at @iter.

getCursorVisible
bool getCursorVisible()

Find out whether the cursor should be displayed.

getEditable
bool getEditable()

Returns the default editability of the GtkTextView.

getExtraMenu
MenuModel getExtraMenu()

Gets the menu model that gets added to the context menu or %NULL if none has been set.

getGutter
Widget getGutter(GtkTextWindowType win)

Gets a GtkWidget that has previously been set as gutter.

getIndent
int getIndent()

Gets the default indentation of paragraphs in @text_view.

getInputHints
GtkInputHints getInputHints()

Gets the input-hints of the GtkTextView.

getInputPurpose
GtkInputPurpose getInputPurpose()

Gets the input-purpose of the GtkTextView.

getIterAtLocation
bool getIterAtLocation(TextIter iter, int x, int y)

Retrieves the iterator at buffer coordinates @x and @y.

getIterAtPosition
bool getIterAtPosition(TextIter iter, int trailing, int x, int y)

Retrieves the iterator pointing to the character at buffer coordinates @x and @y.

getIterLocation
void getIterLocation(TextIter iter, GdkRectangle location)

Gets a rectangle which roughly contains the character at @iter.

getJustification
GtkJustification getJustification()

Gets the default justification of paragraphs in @text_view.

getLeftMargin
int getLeftMargin()

Gets the default left margin size of paragraphs in the @text_view.

getLineAtY
void getLineAtY(TextIter targetIter, int y, int lineTop)

Gets the GtkTextIter at the start of the line containing the coordinate @y.

getLineYrange
void getLineYrange(TextIter iter, int y, int height)

Gets the y coordinate of the top of the line containing @iter, and the height of the line.

getLtrContext
PgContext getLtrContext()

Gets the PangoContext that is used for rendering LTR directed text layouts.

getMonospace
bool getMonospace()

Gets whether the GtkTextView uses monospace styling.

getOverwrite
bool getOverwrite()

Returns whether the GtkTextView is in overwrite mode or not.

getPixelsAboveLines
int getPixelsAboveLines()

Gets the default number of pixels to put above paragraphs.

getPixelsBelowLines
int getPixelsBelowLines()

Gets the default number of pixels to put below paragraphs.

getPixelsInsideWrap
int getPixelsInsideWrap()

Gets the default number of pixels to put between wrapped lines inside a paragraph.

getRightMargin
int getRightMargin()

Gets the default right margin for text in @text_view.

getRtlContext
PgContext getRtlContext()

Gets the PangoContext that is used for rendering RTL directed text layouts.

getTabs
PgTabArray getTabs()

Gets the default tabs for @text_view.

getTopMargin
int getTopMargin()

Gets the top margin for text in the @text_view.

getVisibleRect
void getVisibleRect(GdkRectangle visibleRect)

Fills @visible_rect with the currently-visible region of the buffer, in buffer coordinates.

getWrapMode
GtkWrapMode getWrapMode()

Gets the line wrapping for the view.

imContextFilterKeypress
bool imContextFilterKeypress(Event event)

Allow the GtkTextView input method to internally handle key press and release events.

moveMarkOnscreen
bool moveMarkOnscreen(TextMark mark)

Moves a mark within the buffer so that it's located within the currently-visible text area.

moveOverlay
void moveOverlay(Widget child, int xpos, int ypos)

Updates the position of a child.

moveVisually
bool moveVisually(TextIter iter, int count)

Move the iterator a given number of characters visually, treating it as the strong cursor position.

placeCursorOnscreen
bool placeCursorOnscreen()

Moves the cursor to the currently visible region of the buffer.

remove
void remove(Widget child)

Removes a child widget from @text_view.

resetCursorBlink
void resetCursorBlink()

Ensures that the cursor is shown.

resetImContext
void resetImContext()

Reset the input method context of the text view if needed.

scrollMarkOnscreen
void scrollMarkOnscreen(TextMark mark)

Scrolls @text_view the minimum distance such that @mark is contained within the visible area of the widget.

scrollToIter
bool scrollToIter(TextIter iter, double withinMargin, bool useAlign, double xalign, double yalign)

Scrolls @text_view so that @iter is on the screen in the position indicated by @xalign and @yalign.

scrollToMark
void scrollToMark(TextMark mark, double withinMargin, bool useAlign, double xalign, double yalign)

Scrolls @text_view so that @mark is on the screen in the position indicated by @xalign and @yalign.

setAcceptsTab
void setAcceptsTab(bool acceptsTab)

Sets the behavior of the text widget when the <kbd>Tab</kbd> key is pressed.

setBottomMargin
void setBottomMargin(int bottomMargin)

Sets the bottom margin for text in @text_view.

setBuffer
void setBuffer(TextBuffer buffer)

Sets @buffer as the buffer being displayed by @text_view.

setCursorVisible
void setCursorVisible(bool setting)

Toggles whether the insertion point should be displayed.

setEditable
void setEditable(bool setting)

Sets the default editability of the GtkTextView.

setExtraMenu
void setExtraMenu(MenuModel model)

Sets a menu model to add when constructing the context menu for @text_view.

setGutter
void setGutter(GtkTextWindowType win, Widget widget)

Places @widget into the gutter specified by @win.

setIndent
void setIndent(int indent)

Sets the default indentation for paragraphs in @text_view.

setInputHints
void setInputHints(GtkInputHints hints)

Sets the input-hints of the GtkTextView.

setInputPurpose
void setInputPurpose(GtkInputPurpose purpose)

Sets the input-purpose of the GtkTextView.

setJustification
void setJustification(GtkJustification justification)

Sets the default justification of text in @text_view.

setLeftMargin
void setLeftMargin(int leftMargin)

Sets the default left margin for text in @text_view.

setMonospace
void setMonospace(bool monospace)

Sets whether the GtkTextView should display text in monospace styling.

setOverwrite
void setOverwrite(bool overwrite)

Changes the GtkTextView overwrite mode.

setPixelsAboveLines
void setPixelsAboveLines(int pixelsAboveLines)

Sets the default number of blank pixels above paragraphs in @text_view.

setPixelsBelowLines
void setPixelsBelowLines(int pixelsBelowLines)

Sets the default number of pixels of blank space to put below paragraphs in @text_view.

setPixelsInsideWrap
void setPixelsInsideWrap(int pixelsInsideWrap)

Sets the default number of pixels of blank space to leave between display/wrapped lines within a paragraph.

setRightMargin
void setRightMargin(int rightMargin)

Sets the default right margin for text in the text view.

setTabs
void setTabs(PgTabArray tabs)

Sets the default tab stops for paragraphs in @text_view.

setTopMargin
void setTopMargin(int topMargin)

Sets the top margin for text in @text_view.

setWrapMode
void setWrapMode(GtkWrapMode wrapMode)

Sets the line wrapping for the view.

startsDisplayLine
bool startsDisplayLine(TextIter iter)

Determines whether @iter is at the start of a display line.

windowToBufferCoords
void windowToBufferCoords(GtkTextWindowType win, int windowX, int windowY, int bufferX, int bufferY)

Converts coordinates on the window identified by @win to buffer coordinates.

addOnBackspace
gulong addOnBackspace(void delegate(TextView) dlg, ConnectFlags connectFlags)

Gets emitted when the user asks for it.

addOnCopyClipboard
gulong addOnCopyClipboard(void delegate(TextView) dlg, ConnectFlags connectFlags)

Gets emitted to copy the selection to the clipboard.

addOnCutClipboard
gulong addOnCutClipboard(void delegate(TextView) dlg, ConnectFlags connectFlags)

Gets emitted to cut the selection to the clipboard.

addOnDeleteFromCursor
gulong addOnDeleteFromCursor(void delegate(GtkDeleteType, int, TextView) dlg, ConnectFlags connectFlags)

Gets emitted when the user initiates a text deletion.

addOnExtendSelection
gulong addOnExtendSelection(bool delegate(GtkTextExtendSelection, TextIter, TextIter, TextIter, TextView) dlg, ConnectFlags connectFlags)

Emitted when the selection needs to be extended at @location.

addOnInsertAtCursor
gulong addOnInsertAtCursor(void delegate(string, TextView) dlg, ConnectFlags connectFlags)

Gets emitted when the user initiates the insertion of a fixed string at the cursor.

addOnInsertEmoji
gulong addOnInsertEmoji(void delegate(TextView) dlg, ConnectFlags connectFlags)

Gets emitted to present the Emoji chooser for the @text_view.

addOnMoveCursor
gulong addOnMoveCursor(void delegate(GtkMovementStep, int, bool, TextView) dlg, ConnectFlags connectFlags)

Gets emitted when the user initiates a cursor movement.

addOnMoveViewport
gulong addOnMoveViewport(void delegate(GtkScrollStep, int, TextView) dlg, ConnectFlags connectFlags)

Gets emitted to move the viewport.

addOnPasteClipboard
gulong addOnPasteClipboard(void delegate(TextView) dlg, ConnectFlags connectFlags)

Gets emitted to paste the contents of the clipboard into the text view.

addOnPreeditChanged
gulong addOnPreeditChanged(void delegate(string, TextView) dlg, ConnectFlags connectFlags)

Emitted when preedit text of the active IM changes.

addOnSelectAll
gulong addOnSelectAll(void delegate(bool, TextView) dlg, ConnectFlags connectFlags)

Gets emitted to select or unselect the complete contents of the text view.

addOnSetAnchor
gulong addOnSetAnchor(void delegate(TextView) dlg, ConnectFlags connectFlags)

Gets emitted when the user initiates settings the "anchor" mark.

addOnToggleCursorVisible
gulong addOnToggleCursorVisible(void delegate(TextView) dlg, ConnectFlags connectFlags)

Gets emitted to toggle the cursor-visible property.

addOnToggleOverwrite
gulong addOnToggleOverwrite(void delegate(TextView) dlg, ConnectFlags connectFlags)

Gets emitted to toggle the overwrite mode of the text view.

Meta